<?php
namespace app\controller;

use app\BaseController;
use app\model\Goods;
use app\model\User;
use app\request;
class Index extends BaseController
{
    public function index()
    {
        // return view('index');
         return view('index/page/login');
         echo "hello admin";
        
        
    }
    public function show(){
    	$db = new Goods();
        $index = $db->sho();
        return json($index);
    }
    public function add(){
    	$db = new Goods();
    	$index = $db->inser();
    	return json($index);
    }

    public function update(){
    	$db = new Goods();
    	$index = $db->up();
    	return json($index);
    }

    public function delete(){
    	$db = new Goods();
    	$index = $db->drop();
    	return json($index);
    }

    protected $userObj;

    public function __construct()
    {
        $this->userObj = new User();
    }

    public function login(request $request)
    {
        $user['username'] = $request->post('username','','trim');
        $user['password'] = md5($request->post('username','','trim'));
        $res = $this->userObj->login($user);

        if (empty($res)) {
            return ['code'=>1,'msg'=>'帐号密码错误','data'=>''];
        }
        $res = $res->toarray();
        // Cookie::set('identiey',$res['identity'],60*60);
        Cookie::set('username',$res['username'],60*60);
        return ['code'=>0,'msg'=>'登录成功','data'=>$res];
    }
    
     
}
